package realQuestion.tuyou;

import java.util.Scanner;


public class Main1 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] nums=new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                nums[i][j]=scanner.nextInt();
            }
        }

        int min=Math.min(n,m);
    int maxSum=0;
        for (int i = 0; i <n ; i++) {
            for (int j = 0; j < m; j++) {
                for (int k = 1; k <min ; k++) {
                    if (i+k<n&&j+k<m){
                        int sum=nums[i][j]+nums[i+k][j]+nums[i][j+k]+nums[i+k][j+k];
                        maxSum=Math.max(sum,maxSum);
                    }
                }
            }
        }
        System.out.println(maxSum);
    }

}
